package com.company.koashi;

/**
 * @Author: luosiyu
 * @Description:
 * @Version: 1.0
 */
public class test {
    public static void main(String[] args) {
        System.out.println(new Rect(2,4));
        System.out.println(new Circle(2));
        System.out.println(new Triangle(2,3,4));
    }
}

/**
 * @Author: luosiyu
 * @Description: 接口
 * @Version: 1.0
 */
 interface Shape {
    //    面积
    double area();
    //    周长
    double length();
}

class Rect implements Shape{
    private double a;
    private double b;

    public Rect() {
    }

    public Rect(double a, double b) {
        this.a = a;
        this.b = b;
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    @Override
    public double area() {
        return a*b;
    }

    @Override
    public double length() {
        return (a+b)*2;
    }

    @Override
    public String toString() {
        return "面积="+area()+";周长="+length();
    }

}

class Circle implements Shape{
    private double a;
    public Circle() {
    }

    public Circle(double a) {
        this.a = a;
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    @Override
    public double area() {
        double c = Math.PI*a*a;
        return Double.valueOf(String.format("%.2f",c));
    }

    @Override
    public double length() {
        double c =2*Math.PI*a;
        return Double.valueOf(String.format("%.2f",c));
    }
    @Override
    public String toString() {
        return "面积="+area()+";周长="+length();
    }
}

class Triangle implements Shape{
    private double a;
    private double b;
    private double c;

    public Triangle() {
    }

    public Triangle(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }

    private boolean getTriangleArea(){
        return a+b>c && a+c>b && b+c>a;
    }

    @Override
    public double area() {
        if (getTriangleArea()){
            double p = (a+b+c)/2;
            double d = Math.sqrt(p*(p-a)*(p-b)*(p-c));
            return Double.valueOf(String.format("%.2f",d));
        }
        return -1;
    }

    @Override
    public double length() {
        return getTriangleArea()?a+b+c:-1;
    }
    @Override
    public String toString() {
        return getTriangleArea()?"面积="+area()+";周长="+length():"不构成三角形";
    }
}
